package com.example.yuejianapp14.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejianapp14.Activity.Activity.ViewVideoActivity;
import com.example.yuejianapp14.Activity.JavaBean.Video1;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by jason_lin on 2017/10/16.
 */

public class ClubVideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Video1> mDataList;
    private LayoutInflater mLayoutInflater;

    public ClubVideoAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.videocard,parent,false);
        return new ClubVideoAdapter.ViewHolder(v);
    }
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final Video1 entity = (Video1) mDataList.get(position);
        if (null == entity)
            return;
        ClubVideoAdapter.ViewHolder viewHolder = (ClubVideoAdapter.ViewHolder) holder;
        viewHolder.Video_name.setText(entity.getName());
        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/Thumbnail/"+entity.getThumbnail()).into(viewHolder.Video_pic);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
        public void onClick(View v) {
            Intent intent=new Intent(mContext, ViewVideoActivity.class);
            intent.putExtra("videopath",mDataList.get(position).getVideopath());
            mContext.startActivity(intent);

        }

        });
    }
    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView Video_pic;
        TextView Video_name;
        LinearLayout Video_container;

        public ViewHolder(View itemView) {
            super(itemView);
            Video_name = (TextView) itemView.findViewById(R.id.video_name);
            Video_pic = (ImageView) itemView.findViewById(R.id.video_pic);
            Video_container = (LinearLayout) itemView.findViewById(R.id.video_container);

        }
    }
}
